Apache Configuration
-------------------------------------------------- 
The .htaccess configuration for ContentCourier is relatively straightforward.  It's also required.  ContentCourier can't be used without the ability to configure apache, either via .htaccess files or the apache config itself.

Turning On mod_rewrite
-------------------------------------------------- 
The following two lines turn on the mod_rewrite module, and set the RewriteBase.  If you're deploying ContentCourier to the root level of a web site, you may leave these lines as is.  If you're installing to a sub-folder, you'll want to set RewriteBase to match this folder

    RewriteEngine On
    RewriteBase /
    #RewriteBase /folder

Redirecting www Sub-Domain
-------------------------------------------------- 
While not necessary, uncommenting the following lines and replacing example.com with your domain will ensure that requests made to the www sub-domain are redirected to your primary domain, creating a single, canonical domain for your web site.

    #sends www.example.com to example.com
    #RewriteCond %{HTTP_HOST} ^www\.example\.com
    #RewriteRule ^(.*)$ http://example.com/$1 [R=301]

Redirecting Trailing Slash
-------------------------------------------------- 
The following two lines are another optional config 

    RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)/$ $1 [L,R=301]

This ensures that requests with a trailing slash

    http://example.com/some/path/
    
are redirected to     

    http://example.com/some/path

Without this line, ContentCourier would attempt to process the URI /some/path<strong>/</strong> (as opposed to /some/path), which is in 99% of the cases not what you want. The

    RewriteCond %{REQUEST_FILENAME} !-d

line ensures that apache will handle requests for existing folders normally.

Intercepting requests
-------------------------------------------------- 
Finally, the main bit of .htaccess config, which ensure all requests are routed through ContentCourier

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?uri=$1 [L,QSA]

Again, the RewriteCond lines ensure that files that exist on the host web server are served out normally. This may cause problems under extremely high load, as apache has to check if the files and/or directories exist.

.htaccess vs. httpd.conf
-------------------------------------------------- 
The mod_rewrite module operates differently in the context of an httpd.conf file.  Two differences of concern are 

1. The initial URI that the RewriteRules check against contains a starting slash [/]

2. RewriteBase does not exist.  

ContentCourier was written assuming an .htaccess deployment.  However, there's nothing stopping you from modifying the above .htaccess rules for use in httpd.conf. This is left as an exercise for the reader, and if the reader isn't up to it we suggest they shouldn't be hacking around in the main apache config. 


